Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bleed-believer/meta

Package Overview
Dependencies
Maintainers
0
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bleed-believer/meta

Manage multiple tags into your objects.

  • 0.11.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
26
decreased by-25.71%
Maintainers
0
Weekly downloads
 
Created
Source

@bleed-believer/meta

Adds metadata easifuly to your objects.

Disclaimer

Since ESM hs been heavely adopted by the whole node.js community (including transpilers, unit testing, and many other libraries), the CJS support has been removed. If you still needs the CJS compatibility, please use this version or earlier.

Installation

Use npm to get the last version:

npm i --save @bleed-believer/meta

Concepts

To understand how this library works, first we need to define some concepts:

Target:

Any object that you want to write inside of, data about itself. It's common, for example, have classes that you need to specify how these classes will be instantiated and used for a particular third party tool or library. So in thoses cases you may need to write data dinamically into the prototype por example.

Metadata:

The data do you want to attach to the target. This data normally describes how to use the target object to another one that requires for it. We use interfaces to describe the structure of a kind of metadata.

How to use

  • First create an interface with the structure of your metadata:

    export interface EndpointMeta {
        path:   string;
        routes: {
            method: string;
            key:    string;
        }[];
    }
    
  • Create a new instance of MetaManager:

    export const ENDPOINT = new MetaManager<EndpointMeta>();
    
  • Now you can attach metadata into your objects:

    import { ENDPOINT } from './endpoint.js';
    
    export class UserController {
        get(): Promise<void> {
            // bla bla bla bla bla bla
        }
        
        set(): Promise<void> {
            // bla bla bla bla bla bla
        }
    }
    
    ENDPOINT.set(UserController, {
        path: 'user',
        routes: [
            { method: 'GET',    key: 'get' },
            { method: 'POST',   key: 'set' },
        ]
    });
    
  • ...or get its metadata:

    import { UserController } from './user.controller.js';
    import { ENDPOINT } from './endpoint.js';
    
    const meta = ENDPOINT.get(UserController);
    console.log(meta);
    // Prints:
    // {
    //     path: 'user',
    //     routes: [
    //         { method: 'GET',    key: 'get' },
    //         { method: 'POST',   key: 'set' },
    //     ]
    // }
    

Keywords

FAQs

Package last updated on 02 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc